﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace baseClass.controls
{
    public partial class employee_identity : UserControl
    {
        private Color saveNormalFC = application.Settings.sysColorNormalFG;
        public employee_identity()
        {
            InitializeComponent();
            saveNormalFC = idCardIdEd.ForeColor;
            idCardIdEd.isToUpperCase = true;
            passportEd.isToUpperCase = true;
            issuranceBookEd.isToUpperCase = true;
            medBookEd.isToUpperCase = true;
            perTaxCodeEd.isToUpperCase = true;
        }
        private void SetMaxLength()
        {
            data.baseDS.employeeDataTable tbl = new data.baseDS.employeeDataTable();
            idCardIdEd.maxlen = tbl.cardIdColumn.MaxLength;
            passportEd.maxlen = tbl.passportNoColumn.MaxLength;
            passportPlaceEd.maxlen = tbl.passportIssuerColumn.MaxLength;

            issuranceBookEd.maxlen = tbl.socialInsuranceNoColumn.MaxLength;
            issuranceBookPlaceEd.maxlen = tbl.socialInsurancePlaceColumn.MaxLength;
            
            medBookEd.maxlen = tbl.medInsuranceNoColumn.MaxLength;
            medBookPlaceEd.maxlen = tbl.medInsurancePlaceColumn.MaxLength;
            medExamCenterEd.maxlen = tbl.medInsuranceCenterColumn.MaxLength;

            perTaxCodeEd.maxlen = tbl.taxCodeColumn.MaxLength;
            perTaxCodeIssuerEd.maxlen = tbl.taxIssuerColumn.MaxLength;
        }

        public virtual void LoadData()
        {
            passportTypeCb.LoadData();
        }
        public virtual void SetData(data.baseDS.employeeRow row)
        {
            idCardIdEd.Text = (row.IscardIdNull() ? "" : row.cardId);
            idCardDateEd.myDateTime = (row.IscardDateNull() ? common.Consts.constNullDate: row.cardDate);
            idCardPlaceEd.Text = (row.IscardIssuerNull() ? "" : row.cardIssuer);

            passportEd.Text = (row.IscardIdNull() ? "" : row.cardId);
            passportDateEd.myDateTime = (row.IspassportDateNull() ? common.Consts.constNullDate : row.passportDate);
            passportExpDateEd.myDateTime = (row.IspassportExpDateNull() ? common.Consts.constNullDate: row.passportExpDate);
            passportTypeCb.myValue = (row.IspassportTypeNull() ? "" : row.passportType);
            passportPlaceEd.Text = (row.IspassportIssuerNull() ? "" : row.passportIssuer);

            issuranceBookEd.Text = (row.IssocialInsuranceNoNull() ? "" : row.socialInsuranceNo);
            issuranceBookDateEd.myDateTime = (row.IssocialInsuranceDateNull() ? common.Consts.constNullDate : row.socialInsuranceDate);
            issuranceBookPlaceEd.Text = (row.IssocialInsurancePlaceNull() ? "" : row.socialInsurancePlace);

            medBookEd.Text = (row.IsmedInsuranceNoNull() ? "" : row.medInsuranceNo);
            medBookFrDateEd.myDateTime = (row.IsmedInsuranceFrDateNull() ? common.Consts.constNullDate : row.medInsuranceFrDate);
            medBookToDateEd.myDateTime = (row.IsmedInsuranceToDateNull() ? common.Consts.constNullDate : row.medInsuranceToDate);
            medBookPlaceEd.Text = (row.IsmedInsurancePlaceNull() ? "" : row.medInsurancePlace);
            medExamCenterEd.Text = (row.IsmedInsuranceCenterNull() ? "" : row.medInsuranceCenter);

            perTaxCodeEd.Text = (row.IstaxCodeNull() ? "" : row.taxCode);
            perTaxCodeIssuerEd.Text = (row.IstaxIssuerNull() ? "" : row.taxIssuer);
        }
        public virtual void GetData(data.baseDS.employeeRow row)
        {
            if (idCardIdEd.Text.Trim()=="") row.SetcardIdNull(); else row.cardId = idCardIdEd.Text.Trim();
            if (idCardDateEd.myDateTime == common.Consts.constNullDate) row.SetcardDateNull(); else row.cardDate = idCardDateEd.myDateTime;
            if (idCardPlaceEd.Text.Trim() == "") row.SetcardIssuerNull(); else row.cardIssuer = idCardPlaceEd.Text.Trim();

            if (passportEd.Text.Trim() == "") row.SetpassportNoNull(); else row.passportNo = passportEd.Text.Trim();
            if (passportTypeCb.myValue.Trim() == "") row.SetpassportTypeNull(); else row.passportType = passportTypeCb.myValue.Trim();
            if (passportDateEd.myDateTime == common.Consts.constNullDate) row.SetpassportDateNull(); else row.passportDate = passportDateEd.myDateTime;
            if (passportExpDateEd.myDateTime == common.Consts.constNullDate) row.SetpassportExpDateNull(); else row.passportExpDate = passportExpDateEd.myDateTime;
            if (passportPlaceEd.Text.Trim() == "") row.SetpassportIssuerNull(); else row.passportIssuer = passportPlaceEd.Text.Trim();

            if (issuranceBookEd.Text.Trim() == "") row.SetsocialInsuranceNoNull(); else row.socialInsuranceNo = issuranceBookEd.Text.Trim();
            if (issuranceBookDateEd.myDateTime == common.Consts.constNullDate) row.SetsocialInsuranceDateNull(); else row.socialInsuranceDate = issuranceBookDateEd.myDateTime;
            if (issuranceBookPlaceEd.Text.Trim() == "") row.SetsocialInsurancePlaceNull(); else row.socialInsurancePlace = issuranceBookPlaceEd.Text.Trim();

            if (medBookEd.Text.Trim() == "") row.SetmedInsuranceNoNull(); else row.medInsuranceNo = medBookEd.Text.Trim();
            if (medBookFrDateEd.myDateTime == common.Consts.constNullDate) row.SetmedInsuranceFrDateNull(); else row.medInsuranceFrDate = medBookFrDateEd.myDateTime;
            if (medBookToDateEd.myDateTime == common.Consts.constNullDate) row.SetmedInsuranceToDateNull(); else row.medInsuranceToDate = medBookToDateEd.myDateTime;
            if (medBookPlaceEd.Text.Trim() == "") row.SetmedInsurancePlaceNull(); else row.medInsurancePlace = medBookPlaceEd.Text.Trim();
            if (medExamCenterEd.Text.Trim() == "") row.SetmedInsuranceCenterNull(); else row.medInsuranceCenter = medExamCenterEd.Text.Trim();

            if (perTaxCodeEd.Text.Trim() == "") row.SettaxCodeNull(); else row.taxCode = perTaxCodeEd.Text.Trim();
            if (perTaxCodeIssuerEd.Text.Trim() == "") row.SettaxIssuerNull(); else row.taxIssuer = perTaxCodeIssuerEd.Text.Trim();
        }
        public virtual bool CheckData()
        {
            bool retVal = true;
            idCardDateLbl.ForeColor = saveNormalFC;
            idCardPlaceLbl.ForeColor = saveNormalFC;
            if (idCardIdEd.Text.Trim() != "")
            {
                if (idCardDateEd.myDateTime == common.Consts.constNullDate)
                {
                    idCardDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (idCardPlaceEd.Text.Trim() == "")
                {
                    idCardPlaceLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }

            passportDateLbl.ForeColor = saveNormalFC;
            passportExpDateLbl.ForeColor = saveNormalFC;
            passportPlaceEd.ForeColor = saveNormalFC;
            passportTypeLbl.ForeColor = saveNormalFC;
            if (passportEd .Text.Trim() != "")
            {
                if (passportDateEd.myDateTime == common.Consts.constNullDate)
                {
                    passportDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (passportExpDateEd.myDateTime == common.Consts.constNullDate)
                {
                    passportExpDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (passportTypeCb.myValue.Trim()  == "")
                {
                    passportTypeLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (passportPlaceEd.Text == "")
                {
                    passportPlaceLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }

            issuranceBookDateLbl.ForeColor = saveNormalFC;
            issuranceBookPlaceLbl.ForeColor = saveNormalFC;
            if (issuranceBookEd.Text.Trim() != "")
            {
                if (issuranceBookDateEd.myDateTime == common.Consts.constNullDate)
                {
                    issuranceBookDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (issuranceBookPlaceEd.Text.Trim()=="")
                {
                    issuranceBookPlaceLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }

            mediBookFrDateLbl.ForeColor = saveNormalFC;
            mediBookToDateLbl.ForeColor = saveNormalFC;
            mediBookPlaceLbl.ForeColor = saveNormalFC;
            if (medBookEd.Text.Trim() != "")
            {
                if (medBookFrDateEd.myDateTime == common.Consts.constNullDate)
                {
                    mediBookFrDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (medBookToDateEd.myDateTime == common.Consts.constNullDate)
                {
                    mediBookToDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (medBookPlaceEd.Text.Trim() == "")
                {
                    mediBookPlaceLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            idCardIdEd.ReadOnly = state;
            idCardDateEd.ReadOnly = state;
            idCardPlaceEd.ReadOnly = state;
            
            passportEd.ReadOnly = state;
            passportTypeCb.Enabled = !state;
            passportDateEd.ReadOnly = state;
            passportExpDateEd.ReadOnly = state;
            passportPlaceEd.ReadOnly = state;

            issuranceBookEd.ReadOnly = state;
            issuranceBookDateEd.ReadOnly = state;
            issuranceBookPlaceEd.ReadOnly = state;

            medBookEd.ReadOnly = state;
            medBookFrDateEd.ReadOnly = state;
            medBookToDateEd.ReadOnly = state;
            medBookPlaceEd.ReadOnly = state;
            medExamCenterEd.ReadOnly = state;

            perTaxCodeEd.ReadOnly = state;
            perTaxCodeIssuerEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            idCardIdEd.Focus();
        }
    }
}
